<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 2.准备容器 -->
  <div id="app">
    <h1>双项绑定</h1>
    <label>用户：<input type="text" v-model="username"></label>
    <br>
    <br>
    <label>密码：<input type="password" v-model="password"></label>
    <br>
    <br>
    <button @click="submit()">登录</button>
    <button @click="reset()">重置</button>
    <p>数据1：{{username}}</p>
    <p>数据2：{{password}}</p>
  </div>
  <!-- 1.导入vue.js -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

  <script>
    // 3创建实例化对象
    const app = new Vue({
      // 容器id
      el: '#app',
      // 数据
      data: {
        username: '',
        password: ''
      },
      methods: {
        submit() {
          alert(`登录数据为${this.username},${this.password}`)
          this.reset()
          return
        },
        reset() {
          this.username = "";
          this.password = ""
        }
      }
    })
  </script>
</body>

</html>